package com.jay.lang.annotation.intf;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

@MyAnnotation3(value1 = "xxx")
@MyAnnotation2(value1 = "class", value2 = 234)
public class AnnotationIntf {
	public static void main(String[] args) throws NoSuchMethodException,
			SecurityException {

		System.out.println(MyAnnotation1.class);
		System.out.println(MyAnnotation1.class.isAnnotation());
		System.out.println(AnnotationIntf.class
				.isAnnotationPresent(MyAnnotation1.class));
		System.out.println(AnnotationIntf.class
				.isAnnotationPresent(MyAnnotation2.class));
		System.out.println(AnnotationIntf.class
				.isAnnotationPresent(MyAnnotation3.class));

		// getAnnotations
		Annotation[] annos = AnnotationIntf.class.getAnnotations();
		System.out.println("All annotations for AnnotationIntf:");
		for (Annotation a : annos) {
			System.out.println(a);
			System.out.println(a.annotationType());
		}

		annos = AnnotationIntf.class.getDeclaredAnnotations();
		System.out.println("All declared annotations for AnnotationIntf:");
		for (Annotation a : annos) {
			System.out.println(a);
			System.out.println(a.annotationType());
		}

		Method m = AnnotationIntf.class.getDeclaredMethod("myMethod");

		Annotation[] annosM = m.getDeclaredAnnotations();
		System.out.println("All declared annotations for method myMethod:");
		for (Annotation a : annosM) {
			System.out.println(a);
			System.out.println(a.annotationType());
		}
		
		MyAnnotation1 ma = m.getAnnotation(MyAnnotation1.class) ;
		System.out.println(ma.value1());
		System.out.println(ma.value2());
	}

	@MyAnnotation1(value1 = "method", value2 = 123)
	void myMethod() {

	}
}
